﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cotizav.CONEXION;

namespace Cotizav.PRESENTACION.DialogBox
{
    public partial class DialogMessageBoxList : Form
    {
        private string titulo;
        private string descripcion;        
        private object listObject;
        private string className;

        public string Titulo
        {
            get { return titulo; }
            set { titulo = value; }
        }
        
        public string Descripcion
        {
            get { return descripcion; }
            set { descripcion = value; }
        }
        
        public object ListObject
        {
            get { return listObject; }
            set { listObject = value; }
        }

        public string ClassName
        {
            get { return className; }
            set { className = value; }
        }

        
        public DialogMessageBoxList()
        {
            InitializeComponent();
        }

        public DialogMessageBoxList(string titulo, string descripcion, object list, string className ) : this()
        {
            Titulo = titulo;
            Descripcion = descripcion;
            ListObject = list;
            ClassName = className;
        }

        private void DialogMessageBoxList_Load(object sender, EventArgs e)
        {
            this.Text = Titulo;
            this.lblDescripcion.Text = Descripcion;

            //cargamos el dataGridView
            this.loadObjectList();
        }

        internal void loadObjectList()
        {
            switch (ClassName)
            {
                case "Cliente":
                    List<CLIENTE> clientes = ListObject as List<CLIENTE>;

                    gridListObject.DataSource = null;
                    gridListObject.DataSource = clientes;
                    break;

                case "Vendedor":
                    List<VENDEDOR> vendedores = ListObject as List<VENDEDOR>;

                    gridListObject.DataSource = null;
                    gridListObject.DataSource = vendedores;
                    break;
            }
        }

        private void gridListObject_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (gridListObject.DataSource != null)
            {
                switch (ClassName)
                {
                    case "Cliente":
                        gridListObject.Columns["idCliente"].Visible = false;
                        gridListObject.Columns["direccion"].HeaderText = "Dirección";
                        gridListObject.Columns["direccion"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["provincia"].Visible = false;
                        gridListObject.Columns["email"].Visible = false;
                        gridListObject.Columns["razonSocial"].HeaderText = "Cliente";
                        gridListObject.Columns["razonSocial"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["razonSocial"].DisplayIndex = 2;
                        gridListObject.Columns["idcategoria"].Visible = false;
                        gridListObject.Columns["idsector"].Visible = false;
                        gridListObject.Columns["idDistrito"].Visible = false;
                        gridListObject.Columns["idSucursal"].Visible = false;
                        gridListObject.Columns["clienteruc"].HeaderText = "R.U.C.";
                        gridListObject.Columns["clienteruc"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["clienteruc"].DisplayIndex = 1;
                        gridListObject.Columns["telefono"].Visible = false;
                        gridListObject.Columns["eliminado"].Visible = false;
                        gridListObject.Columns["idVendedor"].Visible = false;
                        gridListObject.Columns["fechaRegistro"].Visible = false;
                        gridListObject.Columns["fechaModificacion"].Visible = false;
                        gridListObject.Columns["registradoPor"].Visible = false;
                        gridListObject.Columns["CATEGORIA"].Visible = false;
                        gridListObject.Columns["SECTOR"].Visible = false;
                        gridListObject.Columns["VENDEDOR"].Visible = false;
                        gridListObject.Columns["DISTRITO"].Visible = false;
                        break;
                    
                    case "Vendedor":
                        gridListObject.Columns["idVendedor"].Visible = false;
                        gridListObject.Columns["nombre"].HeaderText = "Vendedor";
                        gridListObject.Columns["nombre"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["codigoEmpleado"].HeaderText = "Código";
                        gridListObject.Columns["idVendedor"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["telefono"].HeaderText = "Teléfono";
                        gridListObject.Columns["telefono"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        gridListObject.Columns["anexo"].Visible = false;
                        gridListObject.Columns["celular"].Visible = false;
                        gridListObject.Columns["nextel"].Visible = false;
                        gridListObject.Columns["fax"].Visible = false;
                        gridListObject.Columns["rpc"].Visible = false;
                        gridListObject.Columns["rpm"].Visible = false;
                        gridListObject.Columns["email"].Visible = false;
                        gridListObject.Columns["idCargo"].Visible = false;
                        gridListObject.Columns["eliminado"].Visible = false;
                        gridListObject.Columns["fechaRegistro"].Visible = false;
                        gridListObject.Columns["fechaModificacion"].Visible = false;
                        gridListObject.Columns["CARGO"].Visible = false;
                        break;
                }
            }
        }
    }
}
